<?php
/**
 * Created by PhpStorm.
 * User: mojie126
 * Date: 2017/10/10 0010
 * Time: 下午 16:24
 */

namespace app\index\controller;


class MessageController extends Base
{
	public function send($from, $to, $msg = "", $uuid = "", $level = 1)
	{
		$insert = [
			"level" => $level,
			"time" => nowtime(),
			"content" => $msg,
			"sender" => $from,
			"receiver" => $to,
			"handler" => $from,
			"uuid" => CreateUUID()
		];
		try {
			db()->transaction(function () use ($uuid, $insert, $from) {
				db("message")->where("uuid", $uuid)->update(["status" => 1, "handler" => $from]);
				db("message")->insert($insert);
			});
			jsonReturn(1, "发送成功");
		} catch (\Exception $exception) {
			jsonReturn(0, "发送失败");
		}
	}
}